<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>新能源汽车销售数据分析</title>
    <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap@5.2.3/dist/css/bootstrap.min.css">
    <style>
        body {
            font-family: "Microsoft YaHei", sans-serif;
            background-color: #f8f9fa;
        }
        .navbar {
            background-color: #2c7fb8 !important;
        }
        .navbar-brand {
            font-weight: bold;
            color: white !important;
        }
        .main-container {
            display: flex;
            min-height: calc(100vh - 56px);
        }
        .content-area {
            flex: 1;
            padding: 20px;
            overflow-y: auto;
        }
        .sidebar {
            width: 280px;
            background-color: #f1f1f1;
            padding: 20px 0;
            overflow-y: auto;
            border-right: 1px solid #ddd;
            height: calc(100vh - 56px);
        }
        .nav-link {
            color: #333;
            padding: 10px 20px;
            border-left: 4px solid transparent;
            transition: all 0.3s;
        }
        .nav-link:hover, .nav-link.active {
            background-color: #e9ecef;
            border-left: 4px solid #2c7fb8;
        }
        .chart-container {
            background-color: white;
            border-radius: 8px;
            box-shadow: 0 2px 10px rgba(0,0,0,0.05);
            padding: 20px;
            margin-bottom: 20px;
        }
        .chart-image {
            width: 100%;
            border-radius: 4px;
            margin-bottom: 20px;
        }
        .analysis-text {
            background-color: #f8f9fa;
            border-left: 4px solid #2c7fb8;
            padding: 15px;
            border-radius: 0 4px 4px 0;
        }
        .metrics-card {
            margin-bottom: 20px;
        }
        .hidden {
            display: none;
        }
    </style>
</head>
<body>
    <nav class="navbar navbar-expand-lg navbar-dark bg-primary">
        <div class="container-fluid">
            <a class="navbar-brand" href="#">新能源汽车销售数据分析系统</a>
        </div>
    </nav>

    <div class="main-container">
        <!-- 右侧导航栏 -->
        <div class="content-area">
            <!-- 核心指标卡片 -->
            <div class="row metrics-card">
                <div class="col-12">
                    <div class="chart-container">
                        <h2 class="mb-4">核心市场指标</h2>
                        <div class="row">
                            <div class="col-md-3 mb-3">
                                <div class="card">
                                    <div class="card-body">
                                        <h5 class="card-title">市场总销量</h5>
                                        <p class="card-text display-6">{{ metrics['市场总销量（辆）'] }}</p>
                                    </div>
                                </div>
                            </div>
                            <div class="col-md-3 mb-3">
                                <div class="card">
                                    <div class="card-body">
                                        <h5 class="card-title">平均价格</h5>
                                        <p class="card-text display-6">{{ metrics['平均价格（万元）'] }}万</p>
                                    </div>
                                </div>
                            </div>
                            <div class="col-md-3 mb-3">
                                <div class="card">
                                    <div class="card-body">
                                        <h5 class="card-title">销量冠军品牌</h5>
                                        <p class="card-text display-6">{{ metrics['销量冠军品牌'] }}</p>
                                    </div>
                                </div>
                            </div>
                            <div class="col-md-3 mb-3">
                                <div class="card">
                                    <div class="card-body">
                                        <h5 class="card-title">平均续航里程</h5>
                                        <p class="card-text display-6">{{ metrics['平均续航里程（km）'] }}km</p>
                                    </div>
                                </div>
                            </div>
                        </div>
                    </div>
                </div>
            </div>

            <!-- 图表展示区 -->
            {% for chart in charts %}
            <div id="{{ chart.id }}-container" class="chart-section {% if not loop.first %}hidden{% endif %}">
                <div class="chart-container">
                    <h2>{{ chart.name }}</h2>
                    <img src="{{ url_for('static', filename=chart.img) }}" class="chart-image" alt="{{ chart.name }}">
                    <div class="analysis-text">
                        {{ chart.analysis.replace('\n', '<br>') | safe }}
                    </div>
                </div>
            </div>
            {% endfor %}
        </div>

        <!-- 右侧导航栏 -->
        <div class="sidebar">
            <h5 class="px-3 pb-2">图表导航</h5>
            <div class="nav flex-column">
                {% for chart in charts %}
                <a class="nav-link {% if loop.first %}active{% endif %}" 
                   href="#{{ chart.id }}" 
                   onclick="showChart('{{ chart.id }}')">
                    {{ chart.name }}
                </a>
                {% endfor %}
            </div>
        </div>
    </div>

    <script src="https://cdn.jsdelivr.net/npm/bootstrap@5.2.3/dist/js/bootstrap.bundle.min.js"></script>
    <script>
        function showChart(chartId) {
            // 隐藏所有图表
            document.querySelectorAll('.chart-section').forEach(section => {
                section.classList.add('hidden');
            });
            
            // 显示选中的图表
            document.getElementById(chartId + '-container').classList.remove('hidden');
            
            // 更新导航项样式
            document.querySelectorAll('.nav-link').forEach(item => {
                item.classList.remove('active');
            });
            
            // 获取当前点击的导航项并设置为激活状态
            document.querySelector(`.nav-link[href="#${chartId}"]`).classList.add('active');
        }
    </script>
</body>
</html>